#include <comm_handler.hpp>
#include <commander.hpp>
#include <protocol.hpp>
#include <settings.hpp>

static CommHandler* s_CommHandler = nullptr;

CommHandler* CommHandler::Instance()
{
	if (s_CommHandler == nullptr)
	{
		s_CommHandler = new CommHandler();
	}
	return s_CommHandler;
}

CommHandler::CommHandler()
{
}

CommHandler::~CommHandler()
{
}

bool CommHandler::HandlerExec(uint16_t type, char* buff, int size)
{
	switch (type)
	{
		case P_TYPE_HEART:
			break;

		case P_TYPE_COMMAND:
			if (size == sizeof(msg_command_s))
			{
				msg_command_s* p = (msg_command_s*)buff;
				LOG("Recv command 0x%X(%u)\n", p->command, p->command);
				Commander::Instance()->Handler(p);
			}
			break;

		default:
			break;
	}

	return true;
}